package com.xiaohe66.web.infrastructure.domain.adapter.im;

import com.xiaohe66.web.domain.im.value.MessageCategory;
import com.xiaohe66.web.domain.im.value.MessageContext;
import com.xiaohe66.web.domain.im.value.MessageId;
import com.xiaohe66.web.domain.im.value.MessageState;
import com.xiaohe66.web.domain.im.value.MessageTitle;
import com.xiaohe66.web.infrastructure.domain.adapter.DataConverter;

/**
 * @author xiaohe
 * @since 2023.09.19 16:02
 */
public interface MessageConverter extends DataConverter {

    default MessageId newId(Long value) {
        return ifPresent(value, MessageId::new);
    }

    default MessageCategory asCategory(Integer category) {
        return ifPresent(category, MessageCategory::valueOf);
    }

    default MessageTitle newTitle(String value) {
        return ifPresent(value, MessageTitle::new);
    }

    default MessageContext newContext(String value) {
        return ifPresent(value, MessageContext::new);
    }

    default MessageState asRead(Integer value) {
        return ifPresent(value, MessageState::valueOf);
    }
}
